package com.neuedu.amqp.consumer.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author 金山
 * 项目：sca-all-in-one
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/6/613:41
 */
@Component
public class SpringRabbitListenerBinding {

    // 消费者1
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct2.queue1"),
            exchange = @Exchange(name = "yyzx.direct2", type = ExchangeTypes.DIRECT),  // type = ExchangeTypes.DIRECT 交换机类型
            key = {"red", "blue"}
    ))
    public void listenDirect2Queue1(String msg) {
        System.out.println("消费者1接收到direct2.queue1的消息：【" + msg + "】");
    }

    // 消费者2
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct2.queue2"),
            exchange = @Exchange(name = "yyzx.direct2", type = ExchangeTypes.DIRECT),  // type = ExchangeTypes.DIRECT 交换机类型
            key = {"red", "yellow"}
    ))
    public void listenDirect2Queue2(String msg) {
        System.out.println("消费者2接收到direct2.queue2的消息：【" + msg + "】");
    }
}
